import React, { Component } from "react";
import { Form, Input, Button,InputNumber } from "antd";
import { apiConfigOccupancy,apiEditConfigOccupancy } from '@/request/hotelRoomStatus'
const { TextArea } = Input;
export default class Configure extends Component {
  constructor() {
    super();
    this.state = {
      configOccupancyId:''
    };
  }
  componentDidMount() {
    this.getData()
  }
  getData = async () => {
    let res = await apiConfigOccupancy()
    if (res.code === 0) {
      if (res.data) {
        this.setState({configOccupancyId: res.data.configOccupancyId})
        this.formRef.setFieldsValue(
          {
            roomOccupancyTime: res.data.roomOccupancyTime,
            buyNotice: res.data.buyNotice,
          }
        );
      }
    }
  }
  onFinish = async (value) => {
    let res = await apiEditConfigOccupancy({...value, configOccupancyId: this.state.configOccupancyId})
    if(res.code === 0){
      React.$message({
        type: 'info',
        content: '保存成功'
      })
    }
  }

  render() {
    return (
      <div className="p-layout-box">
        <div style={{ marginLeft: 20 }}>基本信息</div>
        <div style={{ height: '100%', overflowY: 'auto', padding: 20 }}>
          <Form
            ref={ref => this.formRef = ref}
            onFinish={this.onFinish}
            labelCol={{
              span: 2
            }}
            wrapperCol={{
              span: 20,
            }}
          >
           <Form.Item label="房间入住时间" name='roomOccupancyTime'
              rules={[
                {
                  required: true,
                  message: '请输入房间最多预定天数',
                },
              ]}
              extra='订单最多可预订房晚'
            >
              <InputNumber min='1' style={{ width: 300 }} />
            </Form.Item>
            <Form.Item label="预定须知" name='buyNotice'

              rules={[
                {
                  required: true,
                  message: '请输入预定须知',
                },
              ]}>
              <TextArea rows={8} maxLength={300} style={{ width: 500 }} showCount></TextArea>
            </Form.Item>
            <Form.Item
              style={{ marginTop: 40, }}
              wrapperCol={{
                offset: 4,
                span: 16,
              }}>
              <Button style={{ width: 200 }} type="primary" htmlType="submit" >
                保存
              </Button>
            </Form.Item>
          </Form>
        </div>

      </div >
    )
  }
}